<?php
/**
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package Textbook
* @subpackage User
* @author Aljaz Srebrnic <a2piratesoft@gmail.com>;
* @author E. Pavletič
* @copyright 2008 a2PirateSoftware
* @license GPL License v3 <http://www.gnu.org/copyleft/gpl.html>
*/

require_once('ZNF/Action/Action.php');
require_once('class.CommonAction.php');
require_once(ZNF::MODULES_DIR.'/User/Business/UserDAO.php');

class User_Action_Delete extends ZNF_Action_Action{

    private $userDao;

    public function __construct(){
	$this->userDao = new User_Business_UserDAO();
    }

    public function execute($form, ZNF_Action_ActionMapping $mapping){

		if(intval($_POST['id']) == $_SESSION['id']){
		    try{
		        $this->userDao->delete($_SESSION['id']);
		    }catch(USer_Business_UserDAOException $e){
				$_REQUEST['errors'] = CommonAction::handleException($e, 'User');
		        return $mapping->findForward('failure');
		    }
		    return $mapping->findForward('success');
		}
		else{
		    $translation = new ZNF_Presentation_Translation('User', $_SESSION['znf']['lang']);
		    $errors = new ZNF_Action_ActionErrors();
		    $errors->addError(1, $translation->get('errorUserDelete'));
		    $_REQUEST['errors'] = $errors;
		    return $mapping->findForward('failure');
		}

    }
}


?>